home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWCollec / Include / FWTMap.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  2.2 KB  |  84 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTMap.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWTMAP_H
  11. #define FWTMAP_H
  12.  
  13. #ifndef SLSRTARR_H
  14. #include "SLSrtArr.h"
  15. #endif
  16.  
  17. #ifndef FWPRIDEB_H
  18. #include "FWPriDeb.h"
  19. #endif
  20.  
  21. //========================================================================================
  22. // Struct FW_TPair
  23. //========================================================================================
  24.  
  25. template<class tKey, class tValue>
  26. class FW_TPair
  27. {
  28. public:
  29.     FW_TPair(const tKey& key, const tValue& value)
  30.         : fKey(key), fValue(value) {}
  31.     FW_TPair(const tKey& key)
  32.         : fKey(key), fValue() {}
  33.     
  34.     const tKey    fKey;
  35.     tValue        fValue;
  36. };
  37.  
  38. //========================================================================================
  39. // Class FW_TMap
  40. //========================================================================================
  41.  
  42. template<class tKey, class tValue>
  43. class FW_TMap
  44. {
  45. //----------------------------------------------------------------------------------------
  46. //    Constructors/Destructor
  47. //
  48. public:
  49.     FW_TMap(FW_SortedArray_CompareFunction compare);
  50.     ~FW_TMap();
  51.  
  52.     long GetLength() const;
  53.  
  54.     FW_TPair<tKey, tValue>* Find(FW_TPair<tKey, tValue>* item) const;
  55.         // Find entry in the map whose key matches item->fKey
  56.  
  57.     FW_TPair<tKey, tValue>* Find(const tKey& key) const;
  58.         // Find entry in the map whose key matches key
  59.     
  60.     FW_TPair<tKey, tValue>* Add(FW_TPair<tKey, tValue>* newItem);
  61.         // Add newItem to the map.
  62.  
  63.     FW_TPair<tKey, tValue>* Add(const tKey& key, const tValue& value);
  64.         // Create a pair and and it to the map.
  65.  
  66.     tValue& operator[](const tKey& key);
  67.         // Return a reference to the value for the given key
  68.         // Can be used for 
  69.     
  70. public:
  71.  
  72.     FW_TPair<tKey, tValue>* GetItemAt(long index) const;
  73.         // Return the entry at index.  This method should only be used
  74.         // as a low level accessor, for example in iterating across all
  75.         // entries in the map.  Note that Adding a new entry invalidates
  76.         // any previous index:entry associations.
  77.  
  78. private:
  79.     FW_HSortedArray fRep;
  80. };
  81.  
  82. #endif
  83.  
  84.